% Fig2

tab = readtable('kvj_scatter_uk_resid2.csv');
tab = table2array(tab);

date = tab(:, 1);
debt = tab(:, 2);
spread = tab(:, 3);
vol = tab(:, 4);


xp = linspace(min(debt), max(debt));
yp_h = 0.30 - 0.30 - (0.25 + 0.39) * log(xp);
yp_l = 0.30 - 0.25 * log(xp);

figure('position', [0, 0, 600, 400])
plot(xp, yp_h, 'red', 'LineWidth',1.8)
hold on;
plot(xp, yp_l, 'blue', 'LineWidth',1.8)
hold on;

scatter(debt(vol == 0), spread(vol == 0), 12, 'blue')
hold on;
scatter(debt(vol == 1), spread(vol == 1), 12, 'red')

ylim([0, 3])

xlabel('Debt/GDP');
ylabel('Spread');
legend('High foreign volatility', 'Low foreign volatility');

